<!DOCTYPE html>
  <html>
  <head>
      <meta charset="utf-8">
      <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
      <title>个人中心</title>
      <link rel="stylesheet" type="text/css" href="../../css/api.css" />
      <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    	<link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
      <link rel="stylesheet" type="text/css" href="../../css/common.css" />
      <style>
          html, body {width: 100%;min-height: 100%;background: #fff;}
          .aui-active .aui-bar-tab-label{
            color: #f5a51c
          }
          .login {height:240px;background-image: -webkit-linear-gradient(0deg, #f5c674, #ed824c);/*background-image: url(../../image/personal_bkg.jpg);background-repeat: no-repeat; background-size: cover;*/position: relative;}
      	.login .personal_logo {width: 4rem;height: 4rem;border-radius: 50%;margin: 0 auto 9px;/*position: absolute; top: 60px; left: 20px;*/}
      		.login .userinfo {position: absolute; top: 60px;text-align: center; left: 0; right: 0;}
      		.login .userinfo .title {font-size: 0.8rem; color: #fff;}

      		/* 设置条目 */
      		.item {height: 3rem;line-height: 3rem;padding-left: 0.7rem;background-color: #fff;}
      		.item_ico {float: left;width: 2.3rem;padding: 0.7rem 0.7rem 0.7rem 0;}
      		.item_arrow {float: right;width: 1.5rem;padding: 1rem 0.7rem 1rem 0;}
      		.item span {font-size: 0.7rem;}
          [v-cloak] {
              display: none;
          }
        #tab1 .aui-active{
          color: #f23030;
          border-bottom: 2px solid #f23030;
        }
        .aui-list-item-middle{
          padding-left: 0.75rem;
        }
        .aui-radio:checked{
          background-color: #f23030;
          border: solid 1px #f23030;
        }

        .aui-toast-content{
          color: #fff;
        }
        /*.aui-list{
              background-image: none;
        }*/
        .gifts{
          color:#F62525 !important;
        }
        .giftsMsg{
          width:70% !important
        }
      </style>
  </head>
  <body>
<div id="app" style="box-sizing:border-box" v-cloak>
    <div class="aui-refresh-content">

      <ul class="aui-list aui-media-list">
        <li class="aui-list-item" v-for="(item, i) in msgList" :key="i">
            <div class="aui-media-list-item-inner">

                <div class="aui-list-item-label" style="float:left;width:2rem !important">
                    <input class="aui-radio" type="checkbox" name="radio" :value="item.goods_id" v-model="checkValue"/>
                </div>
                <div class="aui-list-item-media">
                    <div :style="'background:url('+item.logo_pic+') no-repeat center/cover;width:100%;height: 100%;'"></div>
                </div>
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-text">
                        <div class="aui-list-item-title" v-if="item.type!=3">{{item.goods_name}}</div>
                        <div class="aui-list-item-title" v-else>{{item.goods_name}}（{{item.area_type | comMsg}}）</div>
                        <div class="aui-list-item-right gifts">{{item.type | comType}}</div>
                    </div>
                    <div class="aui-info aui-margin-t-5">
                        <div class="aui-info-item price gifts" style="width: 50%;">
                            ￥{{item.price}}
                        </div>

                    </div>
                </div>
            </div>
        </li>

      </ul>
    </div>
    <div style="position:fixed;bottom:0;width:100vw;margin:0 auto;background:#F62525;color:#fff;text-align:center;height:2.4rem;line-height:2.4rem;margin-top: 2rem;" @click="giveProduce">领赠品</div>

</div>

  </body>
  <script type="text/javascript" src="../../script/api.js"></script>
  <script type="text/javascript" src="../../script/zepto.js"></script>
  <script type="text/javascript" src="../../script/vue.min.js"></script>
  <script type="text/javascript" src="../../script/utils.js"></script>
  <script type="text/javascript" src="../../script/common.js"></script>
  <script type="text/javascript" src="../../script/aui-tab.js"></script>
  <script type="text/javascript" src="../../script/aui-scroll.js"></script>
  <script type="text/javascript" src="../../script/aui-pull-refresh.js"></script>
  <script type="text/javascript" src="../../script/aui-toast.js"></script>

  <script type="text/javascript">
  apiready = function(){
    var toast = new auiToast({});
    new Vue({
      el:'#app',
      data:{
          page:1,
          totalpage:'',
          msgList:[],
          checkValue:[],
          giveNum:''
      },
      methods:{
        //领赠品
        giveProduce:function(){
          var _this = this;
          //判断选择了几个
          if(_this.checkValue.length>_this.giveNum){
            toast.fail({
              title:'赠品选择最多'+_this.giveNum+'个',
              duration:1000
            })
            return
          }else if(_this.checkValue.length==0){
            toast.fail({
              title:'赠品至少选择1个',
              duration:1000
            })
            return
          }
        //  console.log(_this.checkValue.join("-"))
          api.openWin({
              name: "order",
              url: '../three_frame/giftOrder.html',
              pageParam: {
                giveIds:_this.checkValue.join("-")
              }
          })

        },
        //刷新
        setRefresh:function() {
            var pullRefresh = new auiPullToRefresh({
                container: document.querySelector('.aui-refresh-content'),
                triggerDistance: 100
            }, function(ret) {

                if (ret.status == "success") {
                    setTimeout(function() {
                        pullRefresh.cancelLoading(); //刷新成功后调用此方法隐藏
                    }, 1500)
                }
            })
        },
        //赠品列表
        giftsLisst:function(){
          var _this = this;
          api.ajax({
              url: window.Url.Freeuser_giveGoods,
              method: 'post',
              data: {
                  values: {
                      token:$api.getStorage('token'),
                      page:_this.page
                  }

              }
          },function(ret, err){
              if (ret.re==1) {
                _this.totalpage = ret.data.sum_page;
                _this.msgList = ret.data.list;
                _this.giveNum = ret.data.give;
                console.log( JSON.stringify( ret ) );
              } else {
                toast.fail({
                  title:ret.info,
                  duration:1000
                })
              }
          });

        }

      },
      mounted:function(){
        this.giftsLisst()
        this.setRefresh()
        //检测到达底部添加下一页内容
        var $_this=this;
        var scroll = new auiScroll({
            listen:true, //是否监听滚动高度，开启后将实时返回滚动高度
            distance:40 //判断到达底部的距离，isToBottom为true
        },function(ret){
            if (ret.isToBottom) {
                $_this.page ++
                if ($_this.page > $_this.totalpage) {
                    $_this.page = $_this.totalpage
                    return
                }
                api.ajax({
                    url: window.Url.Freeuser_giveGoods,
                    method: 'post',
                    data: {
                        values: {
                            token:$api.getStorage('token'),
                            page:$_this.page
                        }
                    },
                    timeout: 300,
                }, function(ret, err) {
                    if (ret) {
                        //  api.alert({ msg: JSON.stringify(ret) });
                        $_this.msgList = $_this.msgList.concat(ret.data.newsList)

                    } else {
                        api.alert({ msg: JSON.stringify(err) });
                    }
                })
            }

        })
      },
      filters:{
        comType:function(val){

          switch (Number(val)) {
            case 1:
              return '普通产品';
              break;
            case 2:
              return '积分产品';
              break;
            case 3:
              return '兑换币产品';
              break;
          }
        },
        comMsg:function(val){
          switch(Number(val)){
            case 0:
              return '兑换产品';
              break;
            case 1:
              return '买赠产品';
              break;

          }
        }
      }
    })
  };
  </script>
  </html>
